$(function(){
	 checkLogin();
	 if(sessionStorage['username']){
		 findAccout();
	 }
	$("#back").bind("tap",goBack);
});

function checkLogin(){
	var userName = sessionStorage['username'];
	if(userName!=null&&userName!=""){
		$("#loginInfo").html("<b style='color:blue'>"+userName+"</b>");
		$("#loginBtn").html("<b style='color:green'>已登录</b>/<a href='#' onclick='logout();'>退出</a>");
		
	}else{
		$("#loginInfo").html("<b style='color:red'>未登陆</b>");
		$("#loginBtn").html("<a href='login.html#loginPage'>登陆</a>/<a href='login.html#registerPage'>注册</a>");
		
	}
}

function findAccout(){
	Newtouch.Ajax.sendParams({userId:sessionStorage['userId']},localStorage['APP_AJAX_PATH']+"/drinkingBar/view/personalSetting.jsp.getAccount",function(data){	
		$("#account").html(data.account);
	},function(err){
		$("#account").html("0");
	});
}

function register(){
	window.location="login.html#registerPage";
}

function toOrderSearch(){
	var userName = sessionStorage['username'];
	if(userName!=null&&userName!=""){
		window.location="orderSearch.html";
	}else{
		$(window).mobileMsgBox({msgText:"请先登录！",delayTime:1000});
		window.location="login.html#loginPage";
	}	
}

function toAddressManagement(){
	var userName = sessionStorage['username'];
	if(userName!=null&&userName!=""){
		window.location="addressManagement.html";
	}else{
		$(window).mobileMsgBox({msgText:"请先登录！",delayTime:1000});
		window.location="login.html#loginPage";
	}	
}

function toShopCart(){
	var userName = sessionStorage['username'];
	if(userName!=null&&userName!=""){
		window.location="shopCart.html";
	}else{
		$(window).mobileMsgBox({msgText:"请先登录！",delayTime:1000});
		window.location="login.html#loginPage";
	}	
}
function goBack(){
   $.mobile.back();
	
}
